//  html代码切换显示
var a_user = document.getElementById("a_user")
var a_book = document.getElementById("a_book")
var a_reader = document.getElementById("a_reader")
var a_borrow = document.getElementById("a_borrow")
var a_back = document.getElementById("a_back")
var hide_list = document.getElementsByClassName("hide");

var user_det = document.getElementById("user_det")
var book_det = document.getElementById("book_det")
var reader_det = document.getElementById("reader_det")
var borrow_det = document.getElementById("borrow_det")
var back_det = document.getElementById("back_det")
var hide_btu = document.getElementsByClassName("hide_btu");


a_user.addEventListener("click",function () {
    hideAll()
    cannelValue()
    user_det.style.display = "flex"
    a_user.style.background = "rgb(243,169,31)"
    a_user.style.color = "#fff"
    a_user.style.fontSize = "18px"
})
a_book.addEventListener("click",function () {
    hideAll()
    cannelValue()
    book_det.style.display = "flex"
    a_book.style.background = "rgb(243,169,31)"
    a_book.style.color = "#fff"
    a_book.style.fontSize = "18px"
})
a_reader.addEventListener("click",function () {
    hideAll()
    cannelValue()
    reader_det.style.display = "flex"
    a_reader.style.background = "rgb(243,169,31)"
    a_reader.style.color = "#fff"
    a_reader.style.fontSize = "18px"
})
a_borrow.addEventListener("click",function () {
    hideAll()
    cannelValue()
    borrow_det.style.display = "flex"
    a_borrow.style.background = "rgb(243,169,31)"
    a_borrow.style.color = "#fff"
    a_borrow.style.fontSize = "18px"
})

a_back.addEventListener("click",function () {
    hideAll()
    cannelValue()
    back_det.style.display = "flex"
    a_back.style.background = "rgb(243,169,31)"
    a_back.style.color = "#fff"
    a_back.style.fontSize = "18px"
})

for(var i = 0;i<hide_btu.length;i++) {
    hide_btu[i].addEventListener('click',function () {
        cannelValue()
    })
}


// 所有新增隐藏
function hideAll() {
    var come_back_list = document.getElementsByClassName("come_back");
    for (var i =0;i < hide_list.length;i++) {
        hide_list[i].style.display = "none"
        come_back_list[i].style.background = "#ccc"
        come_back_list[i].style.color = "#000"
        come_back_list[i].style.fontSize = "16px"
    }
}

// 清空input
function cannelValue() {
    var input_list = document.getElementsByTagName("input")
    for (var i=0;i<input_list.length;i++) {
        input_list[i].value = ""
    }
}

// ---------------------------------------------------------------------------------------
// 具体添加操作

// 添加用户

$("#add_user_btu").click(function () {
    var obj = {
        id: new Date() * 1,
        name: $("#new_user").val(),
        pass: $("#new_passr").val(),
        is_admin: $("#new_admin").val()
    }
    console.log(obj);
    // commonAjax_post(obj, deturl, function (res) {
    //     console.log(res); 
    //  })
})
